package com.example.demo.controller;

import com.example.demo.dto.base.BaseIdReq;
import com.example.demo.dto.req.UserInsReq;
import com.example.demo.dto.req.UserSearchReq;
import com.example.demo.dto.req.UserUpdReq;
import com.example.demo.service.IUserService;
import com.example.demo.util.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wen
 * @date 2022年06月10日 9:59
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private IUserService userService;

    /**
     * 获取用户列表
     */
    @PostMapping(value = "/list")
    public ApiResult getList(@RequestBody UserSearchReq req) {
        return userService.getUserList(req);
    }

    /**
     * 新增用户
     */
    @PostMapping(value = "/insert")
    public ApiResult insert(@RequestBody UserInsReq req) {
        return userService.insertUser(req);
    }

    /**
     * 更新用户
     */
    @PostMapping(value = "/update")
    public ApiResult update(@RequestBody UserUpdReq req) {
        return userService.updateUser(req);
    }

    /**
     * 删除用户
     */
    @PostMapping(value = "/delete")
    public ApiResult delete(@RequestBody BaseIdReq req) {
        return userService.delUser(req);
    }

}
